package com.br.negocio.vo;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
@Table(name = "venda")
@SequenceGenerator(name = "venda_seq", sequenceName = "venda_cod_venda_seq", allocationSize = 1)
@NamedQueries ({
	@NamedQuery(name = "loadAllVenda", query = "from VendaVO"),
	@NamedQuery(name = "findVenda", query = "from VendaVO as e where e.codigo = :codigo"),
	@NamedQuery(name = "findDuplicatedVenda", query = "from VendaVO as e where e.codigo = :codigo")
})
public class VendaVO implements Serializable {
	
	public static final String AGUARDANDO 		= "1";
	public static final String CONCLUIDO	 	= "2";

	private static final long serialVersionUID = 1L;
	
	@Id
	@Column(name = "cod_venda")
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "venda_seq")
	private int codigo;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "cod_cliente")
	@Fetch(FetchMode.JOIN)
	private ClienteVO clienteVO;
	
	@ManyToMany(
			targetEntity= com.br.negocio.vo.ServicoVO.class)
		@JoinTable(name="venda_servico", 
	    joinColumns=
            @JoinColumn(name="cod_venda", referencedColumnName="cod_venda"),
        inverseJoinColumns= 
            @JoinColumn(name="cod_servico", referencedColumnName="cod_servico")
        )
    private List<ServicoVO> listaServico;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column (name = "data_criacao")
	private Date dataCriacao;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column (name = "data_alteracao")
	private Date dataAlteracao;
	
	
	public VendaVO() {

	}
	
	public VendaVO(int codigo, ClienteVO clienteVO) {
		this.codigo = codigo;
		this.clienteVO = clienteVO;
	}

	public int getCodigo() {
		return this.codigo;
	}

	public void setCodigo(int codigo) {
		this.codigo = codigo;
	}

	public ClienteVO getClienteVO() {
		return this.clienteVO;
	}

	public void setClienteVO(ClienteVO clienteVO) {
		this.clienteVO = clienteVO;
	}

	public void setDataAlteracao(Date dataAlteracao) {
		this.dataAlteracao = dataAlteracao;
	}

	public Date getDataAlteracao() {
		return dataAlteracao;
	}

	public void setDataCriacao(Date dataCriacao) {
		this.dataCriacao = dataCriacao;
	}

	public Date getDataCriacao() {
		return dataCriacao;
	}

	/**
	 * @return the listaServico
	 */
	public List<ServicoVO> getListaServico() {
		return listaServico;
	}

	/**
	 * @param listaServico the listaServico to set
	 */
	public void setListaServico(List<ServicoVO> listaServico) {
		this.listaServico = listaServico;
	}

	/**
	 * @return the aguardando
	 */
	public static String getAguardando() {
		return AGUARDANDO;
	}

	/**
	 * @return the concluido
	 */
	public static String getConcluido() {
		return CONCLUIDO;
	}
}